<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
			// 给定一个整数数组 nums 和一个目标值 target，请你在该数组中找出和为目标值的那 两个 整数，
			// 并返回他们的数组下标。
      var twoSum = function (nums, target) {
        let i = nums.length;
        while (i > 1) {
          let last = nums.pop();
          if (nums.indexOf(target - last) > -1) {
            return [nums.indexOf(target - last), nums.length];
          }
          i--;
        }
      };
      // var twoSum = function (nums, target) {
      //   let map = new Map();
      //   for (let i = 0; i < nums.length; i++) {
      //     let dif = target - nums[i];
      //     if (map.has(dif)) {
      //       return [map.get(dif), i];
      //     }
      //     map.set(nums[i], i);
      //   }
      // };
      let arr1 = [3, 2, 4];
      let num = 6;
      console.log(twoSum(arr1, num));
    </script>
  </body>
</html>
